/*
 * @Author: hq
 * @Date: 2022-06-07 11:25:01
 * @LastEditors: hq
 * @LastEditTime: 2022-09-20 16:20:46
 * @Description: your project
 * @version: 1.0
 */
import {
    Message
} from "element-ui";
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [{
        path: "/login",
        name: "Login",
        component: (resolve) => require(["@/views/login/login"], resolve),
    },
    {
        path: "/", //首页
        name: "home",
        component: (resolve) => require(["@/views/Home"], resolve),
        redirect: "/welcome",
        children: [{
                path: "/welcome", //首页
                name: "welcome",
                component: (resolve) => require(["@/views/main/welcome"], resolve),
            },
            //商城管理
            // {
            //     path: "/shopSystem/allShop/shop_list", //商品列表电商
            //     name: "shop_list",
            //     component: (resolve) => require(["@/views/main/shopSystem/allShop/shop_list"], resolve),
            // },
            {
                path: "/shopSystem/allShop/shop_list_offline", //商品列表附近
                name: "shop_list_Offline",
                component: (resolve) => require(["@/views/main/shopSystem/allShop/shop_list_offline"], resolve),
            },
            {
                path: "/shopSystem/allShop/meal/meal_list", //套餐
                name: "meal_list",
                component: (resolve) => require(["@/views/main/shopSystem/allShop/meal/meal_list"], resolve),
            },
            {
                path: "/shopSystem/allShop/voucher/voucher_list", //代金券
                name: "voucher_list",
                component: (resolve) => require(["@/views/main/shopSystem/allShop/voucher/voucher_list"], resolve),
            },
            // {
            //     path: "/shopSystem/allShop/shop_classification", //商品分类
            //     name: "shop_classification",
            //     component: (resolve) => require(["@/views/main/shopSystem/allShop/shop_classification"], resolve),
            // },
            {
                path: "/shopSystem/allShop/shop_comment", //商品评论
                name: "shop_comment",
                component: (resolve) => require(["@/views/main/shopSystem/allShop/shop_comment"], resolve),
            },

            {
                path: "/shopSystem/order/online_order", //电商订单
                name: "online_order",
                component: (resolve) => require(["@/views/main/shopSystem/order/online_order"], resolve),
            },
            {
                path: "/shopSystem/order/offline_order", //线下订单
                name: "online_order",
                component: (resolve) => require(["@/views/main/shopSystem/order/offline_order"], resolve),
            },
            {
                path: "/agent/order_list", //代理订单
                name: "order_list",
                component: (resolve) => require(["@/views/main/agent/order_list"], resolve),
            },
            // {
            //     path: "/shopSystem/order/offline_order", //扫一扫订单
            //     name: "offline_order",
            //     component: (resolve) => require(["@/views/main/shopSystem/order/offline_order"], resolve),
            // },
            //商户
            {
                path: "/merchant/shop_list", //店铺列表
                name: "store_list",
                component: (resolve) => require(["@/views/main/merchant/shop_list"], resolve),
            },
            {
                path: "/merchant/transaction_flow", //交易流水
                name: "transaction_flow",
                component: (resolve) => require(["@/views/main/merchant/transaction_flow"], resolve),
            },
            {
                path: "/merchant/transaction_settlement", //交易结算
                name: "transaction_settlement",
                component: (resolve) => require(["@/views/main/merchant/transaction_settlement"], resolve),
            },
            //积分管理
            {
                path: "/score/record_list", //充值记录
                name: "record_list",
                component: (resolve) => require(["@/views/main/score/record_list"], resolve),
            },
            {
                path: "/score/distribute_list", //分发记录
                name: "distribute_list",
                component: (resolve) => require(["@/views/main/score/distribute_list"], resolve),
            },
            {
                path: "/score/operation", //分发操作
                name: "operation",
                component: (resolve) => require(["@/views/main/score/operation"], resolve),
            },
            // 酒店列表
            {
                path: "/myhotel/hotelInfo/index", //酒店信息
                name: "myhotel_index",
                component: (resolve) => require(["@/views/main/myhotel/hotelInfo/index"], resolve),
            },
            {
                path: "/myhotel/roomType/room_type_list", //房型列表
                name: "room_type_list",
                component: (resolve) => require(["@/views/main/myhotel/roomType/room_type_list"], resolve),
            },
            {
                path: "/myhotel/order/checkIn_list", //入住列表
                name: "checkIn_list",
                component: (resolve) => require(["@/views/main/myhotel/order/checkIn_list"], resolve),
            },
            //聊天
            {
                path: "/chat/chat_list", //聊天列表
                name: "chat_list",
                component: (resolve) => require(["@/views/main/chat/chat_list"], resolve),
            },
        ]
    },
    {
        path: '*',
        name: 'notfount',
        component: (resolve) => require(["@/views/404"], resolve),
    },
    {
        path: "/system",
        name: "system",
        component: (resolve) => require(["@/views/main/system"], resolve),
        redirect: "/welcome",
        children: [{
            path: "/system/welcome",
            name: "system_welcome",
            component: (resolve) => require(["@/views/main/welcome"], resolve),

        }]
    }

]



const router = new VueRouter({
    mode: 'history',
    routes,
    base: "/",
});

router.beforeEach((to, from, next) => {
    let token = sessionStorage.getItem('token') //获取 存储token
    if (to.path !== '/login') { //如果去其他页面
        if (token) { //如果有sessionStorage
            next(); //跳转
        } else {
            // Message({
            //     message: "您还没有登录，请先登录账户",
            //     type: "error",
            //     showClose: true,
            // });
            // alert('您还没有登录，请先登录账户'); //没有就先登录
            next('/login') //还在登录页
        }
    } else {
        next();
    }
    // if (to.path === '/login') {
    //     if (token) {
    //         this.$router.push('/welcome')
    //     }
    //     // sessionStorage.clear(); //清空sessionStorage
    // }
})

const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch((err) => err);
};

export default router